package gemini.pollux.ui.client.page.content.product.producttype.widget;

import gemini.basic.model.ProductType;

import com.google.gwt.event.shared.GwtEvent;

public class ProductTypeTableEvent extends GwtEvent<ProductTypeTableHandler> {

	private static Type<ProductTypeTableHandler> TYPE;

	public static Type<ProductTypeTableHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<ProductTypeTableHandler>();
		return TYPE;
	}
	
	private ProductType productType;
	
	public enum EventType {
		EDIT, DELETE, ADD
	}
	
	private EventType eventType;
	
	public ProductTypeTableEvent(){
		this.eventType = EventType.ADD;
	}
	
	public ProductTypeTableEvent(EventType eventType, ProductType productType){
		this.productType = productType;
		this.eventType = eventType;
	}

	@Override
	protected void dispatch(ProductTypeTableHandler handler) {
		if(eventType.equals(EventType.ADD)){
		handler.onAdd(this);
		} else if(eventType.equals(EventType.DELETE)){
		handler.onDelete(this);
		} else if(eventType.equals(EventType.EDIT)){
		handler.onEdit(this);
		}
	}

	@Override
	public Type<ProductTypeTableHandler> getAssociatedType() {
		return getType();
	}

	public ProductType getProductType() {
		return productType;
	}
}
